/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package genomemap.barratt;

import genomemap.data.ComplementationData;
import genomemap.data.GeneCloneTagDAO;

import javautil.io.IOUtil;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Map;

/**
 *
 * @author stewari1
 */
public class GeneCloneTagFileDAO implements GeneCloneTagDAO {

    /** Field description */
    private final String filePath = "resources/dataCollection/gene_clone_complementation_data.txt";

    /**
     * Constructs ...
     */
    public GeneCloneTagFileDAO() {}

    public ComplementationData getComplementationData() throws Exception {

        Map<String, Collection<String>> tagData = new Hashtable<>();
        String line                             = "";

        try (BufferedReader inFile = new BufferedReader(new FileReader(new File(filePath)))) {

            line = inFile.readLine();

            while (line != null) {

                if (line.length() > 0) {

                    String[] vals                 = IOUtil.getTokens(line, null);
                    Collection<String> cloneNames = new ArrayList<>();

                    for (int i = 1; i < vals.length; i++) {

                        cloneNames.add(vals[i]);
                    }

                    tagData.put(vals[0], cloneNames);
                }

                line = inFile.readLine();
            }
        }

        return new ComplementationData(tagData);
    }
}
